package com.github.ilioili.justdoit.common.config;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by User on 16/6/15.
 */
public class UserInfo {
    private static final String KEY_NAME = "KEY_NAME";
    private static final String KEY_ICON = "KEY_ICON";
    private static final String KEY_IS_LOGINED = "KEY_IS_LOGIN";
    private static final String KEY_ID = "KEY_ID";
    private static SharedPreferences sharedPreferences;

    public static void init(Context context) {
        sharedPreferences = context.getSharedPreferences("UserInfo", Context.MODE_PRIVATE);
    }

    public static void clear() {
        sharedPreferences.edit().clear().apply();
    }

    public static void setUserId(String userId) {
        sharedPreferences.edit().putString(KEY_ID, userId).apply();
    }

    public static String getUserId() {
        return sharedPreferences.getString(KEY_ID, null);
    }

    public static void setName(String name) {
        sharedPreferences.edit().putString(KEY_NAME, name).apply();
    }

    public static String getName() {
        return sharedPreferences.getString(KEY_NAME, "NoName");
    }

    public static void setIconUrl(String iconUrl) {
        sharedPreferences.edit().putString(KEY_ICON, iconUrl).apply();
    }

    public static String getIconUrl() {
        return sharedPreferences.getString(KEY_ICON, "http://");
    }


    public static void setIsLogin(boolean isLogin) {
        sharedPreferences.edit().putBoolean(KEY_IS_LOGINED, isLogin).apply();
    }

    public static boolean isLogin() {
        return sharedPreferences.getBoolean(KEY_IS_LOGINED, false);
    }


}
